package com.example.blog.controller.Friend;

import com.example.blog.pojo.FriendList;
import com.example.blog.pojo.FriendRequest;
import com.example.blog.pojo.Result;
import com.example.blog.service.FriendListService;
import com.example.blog.service.FriendRequestService;
import com.example.blog.util.TokenUtil.GetCookie;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/friends")
public class FriendController {
    @Resource
    private FriendRequestService friendRequestService;
    @Resource
    private FriendListService friendListService;

    //发送好友申请
    @PostMapping("/fromFriendsRequest")
    public Result<T> fromFriendsRequest(@RequestParam Integer friendId, HttpServletRequest request) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return friendRequestService.fromFriendsRequest(friendId, token);
    }

    //查看好友申请列表
    @GetMapping("/showFriendsApply")
    public Result<List<FriendRequest>> showFriendsApply(HttpServletRequest request) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return friendRequestService.showFriendsApply(token);
    }
    //同意或者拒绝好友申请
    @PostMapping("/addFriends")
    public Result<T> addFriends(@RequestParam int friendId, HttpServletRequest request,@RequestParam String isApply) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return friendRequestService.addFriends(friendId,token,isApply);
    }
    //获取好友列表
    @GetMapping("/getFriendList")
    public Result<List<FriendList>> getFriendsList(HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return friendListService.getFriendsList(token);
    }
    //删除好友
    @DeleteMapping("/deleteFriendById")
    public Result<T> deleteFriendById(@RequestParam int friendId, HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return friendListService.deleteFriendById(friendId,token);
    }
}
